home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1124 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.0 KB

  1. From: "Wil Evers" <wil@ittpub.nl>
  2. Message-ID: <009A0FD196D0F860.49803CD1@ittpub.nl>
  3. X-Original-Date: Wed, 17 Apr 96 10:32:06 WET
  4. Path: in2.uu.net!bounce-back
  5. Date: 17 Apr 96 10:00:22 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Organization: -
  8. Newsgroups: comp.std.c++
  9. Subject: Re: exceptions in std lib
  10. X-Vms-Mail-To: IN%"std-c++@ncar.ucar.edu"
  11. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  12.     iQBFAgUBMXTBPuEDnX0m9pzZAQG0iwF/bDQN81Rq1ky9WOPG5WMrjwuAu90vQi4v
  13.     HUhnXSj6TsBUvqJ19ZdUf+XtrET4G9uu
  14.     =KONM
  15.  
  16. In article <317326BE.246CF449@cantrip.org> Nathan Myers <ncm@cantrip.org>
  17. writes:
  18.  
  19. > Before you criticize this, consider what you would expect vector<> 
  20. > to do when it is copying a block of elements from one memory region 
  21. > to another, or deleting a block of elements, and an exception happens 
  22. > in the middle.  Do you stop there, half-done?  Do you copy or delete
  23. > the rest of the elements and leave a hole, then rethrow?  (What if you 
  24. > get another exception while doing the rest?)
  25. > If you propagate the exception, member functions of the vector
  26. > (including the destructor) will probably be called later.  What will
  27. > they find?
  28. > This is a long way of asking: What do you mean by `required to be
  29. > exception-safe'?  If you can define it, then probably the standard
  30. > library ought to meet the definition.
  31.  
  32. It seems to me that Harald Mueller's article in the January '96 issue of
  33. The C++ Report could be a big conceptual help here. Basically, after an
  34. operation on an object has reported an exception, one of three things can
  35. be true:
  36.  
  37. 1. The object is in the state it was before the operation that reported the
  38. exception was tried ('throw and keep'). IMHO this should be the default for
  39. standard library components.
  40.  
  41. 2. Futher operations on the object do not make sense, but it is still
  42. possible to destroy it ('throw and throw away'). For some operations, it
  43. may be impossible or practically infeasible to impose rule (1). Here, the
  44. standard could require the operation's documentation to explicitly state
  45. that this is the case. (Since the only sensible thing we can do with such
  46. an object is to destroy it, the standard could also require that a standard
  47. library object in such a state must throw an exception on every attempted
  48. operation until it is destroyed.)
  49.  
  50. 3. The object is in such an unstable state that it is not even possible to
  51. destroy it. This should never happen. (Note: this implies that exceptions
  52. should never escape from destructors.)
  53.  
  54. Of course, 'exception unsafety' is a cascading problem. It wouldn't make
  55. much sense to require a template taking an argument of a type T to be
  56. throw-and-keep if some of T's operations it depends on are
  57. throw-and-throw-away.
  58.  
  59. - Wil
  60. ---
  61. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  62. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  63. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  64. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  65. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  66.